function fuzzyQueryTree(arr, value) {
  if (!Array.isArray(arr) || arr.length === 0) {
    return [];
  }
  let result = [];
  arr.forEach((item) => {
    if (item.title.indexOf(value) > -1) {
      result == null ? void 0 : result.push(item);
    } else {
      if (item.children && item.children.length > 0) {
        const children = fuzzyQueryTree(item.children, value);
        const obj = { ...item, children };
        if (children && children.length > 0) {
          result == null ? void 0 : result.push(obj);
        }
      }
    }
  });
  return result;
}
;
function getPathByKey(curKey, data, options = { keyProp: "key" }) {
  let result = [];
  const traverse = (curKey2, path, data2) => {
    if (data2.length === 0) {
      return;
    }
    ;
    for (const item of data2) {
      const key = item[options.keyProp];
      path.push(item);
      if (key === curKey2) {
        result = JSON.parse(JSON.stringify(path));
        return result;
      }
      const children = Array.isArray(item.children) ? item.children : [];
      traverse(curKey2, path, children);
      path.pop();
    }
  };
  traverse(curKey, [], data);
  return result;
}
;
function getFuzzyPathByKey(curKey, data, options = { keyProp: "key" }) {
  const paths = [];
  const getPath = (data2, path) => {
    if (data2.length === 0) {
      return;
    }
    for (const item of data2) {
      const key = item[options.keyProp];
      const currentPath = [...path, key];
      const children = Array.isArray(item.children) ? item.children : [];
      paths.push({
        path: currentPath,
        node: item
      });
      getPath(children, currentPath);
    }
  };
  getPath(data, []);
  return paths.filter((item) => item.path.some((path) => path.includes(curKey)));
}
function getNodeByKey(key, arr) {
  let result = null;
  const traverse = (tree) => {
    for (let i = 0; i < tree.length; i++) {
      const node = tree[i];
      if (node.key === key) {
        result = node;
        break;
      }
      if (node.children && Array.isArray(node.children) && node.children.length > 0) {
        traverse(node.children);
      }
    }
  };
  traverse(arr);
  return result;
}
export {
  fuzzyQueryTree,
  getFuzzyPathByKey,
  getNodeByKey,
  getPathByKey
};
//# sourceMappingURL=tree.mjs.map
